#include <iostream>
#include <vector>
#include <set>
#include <algorithm>

void extract(std::string str, std::set<std::string> &str_set)
{
    int i = 0;
    while (i < str.size())
    {
        std::string tmp_str;
        while (i < str.size() && str[i] != ' ' && str[i] != ',' && str[i] != '\'' && str[i] != '.')
        {
            tmp_str.push_back(str[i]);
            i++;
        }
        i++;

        str_set.insert(tmp_str);
        while (i < str.size() && (str[i] == ' ' || str[i] == ',' || str[i] == '\'' || str[i] == '.'))
        {
            i++;
        }
    }
}

bool cmp(std::string a, std::string b)
{
    return a < b;
}

int main()
{
    std::string str;
    std::getline(std::cin, str);
    std::string pre;
    std::cin >> pre;

    std::set<std::string> str_set;
    extract(str, str_set);

    int sz = pre.size();
    std::vector<std::string> sv;
    for (auto it = str_set.begin(); it != str_set.end(); ++it)
    {
        if (it->substr(0, sz) == pre)
        {
            sv.push_back(*it);
        }
    }

    if (sv.size() == 0)
    {
        std::cout << pre << std::endl;
    }
    else
    {
        std::sort(sv.begin(), sv.end(), cmp);

        for (int i = 0; i < sv.size() - 1; i++)
        {
            std::cout << sv[i] << " ";
        }
        std::cout << sv.back() << std::endl;
    }
    return 0;
}